package org.boot.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

@Service
public class AsyncService {

    private static final Logger logger = LoggerFactory.getLogger(AsyncService.class);

    @Async("myExecutor")
    public void async1() {
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        logger.debug("AsyncService.async1 at Before");
    }

    @Async("myExecutor")
    public CompletableFuture<String> async2(String name) {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        logger.debug("AsyncService.async2 at Before");
        return CompletableFuture.completedFuture(name + " async2");
    }
}
